package use.xstream.net;

import java.net.HttpURLConnection;
import java.net.URL;

import android.app.Activity;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

public class Use3rdXstreamNetActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
		try {
	        String url="http://192.168.0.190:11111/shmsa/4android/test_xstream.jsp";
	        HttpURLConnection urlc= (HttpURLConnection)new URL(url).openConnection();
	        XStream xstream =new XStream(new DomDriver());
	        xstream.alias("PscItem", PscItem.class);
	        PscItem psc=(PscItem)xstream.fromXML(urlc.getInputStream());
	        TextView textv=(TextView)findViewById(R.id.text);
	        //textv.setText(xstream.toXML(psc));
	        textv.setText(psc.getName());
	        System.out.println(psc.getName());
	        ImageView imgv=(ImageView)findViewById(R.id.pic);
	        imgv.setImageBitmap(BitmapFactory.decodeByteArray(psc.getPic(), 0, psc.getPic().length));
		}  catch (Exception e) {
			e.printStackTrace();
		}
       
    }
}